﻿using Als.Common.String;
using System.Diagnostics;

namespace Als.Common.File
{
    public class CmdHelper
    {
        private readonly Process _proc = null;
        public CmdHelper()
        {
            _proc = new Process();
        }

        public void Exe(string cmd)
        {
            _proc.StartInfo.CreateNoWindow = true;
            _proc.StartInfo.FileName = "cmd.exe";
            _proc.StartInfo.UseShellExecute = false;
            _proc.StartInfo.RedirectStandardInput = true;
            _proc.StartInfo.RedirectStandardOutput = true;
            _proc.StartInfo.RedirectStandardError = true;

           // proc.OutputDataReceived += new DataReceivedEventHandler(sortProcess_OutputDataReceived);
            _proc.Start();
            var cmdWriter = _proc.StandardInput;
            _proc.BeginOutputReadLine();
            if (cmd.IsNullOrEmpty())
            {
                cmdWriter.WriteLine(cmd);
            }
            cmdWriter.Close();          
            _proc.Close();
        }
      
        private void sortProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data.IsNullOrEmpty())
            {
                //this.BeginInvoke(new Action(() => { this.listBox1.Items.Add(e.Data); }));
            }
        }

    }
}
